﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq ;

using NUnit.Framework; 
using DbSharp.Framework.CaseFile;
using DbSharp.Framework.CaseFile.Parser;
using System.Data;

namespace UnitTestProject.CaseFile
{

    [TestFixture]
    public class DbConnectionTest
    {
     
        [Test]
        public void TestConnectionString()
        {
            string testCaseFile = @"CaseFileSample\TestCase_V2_DbConn_3Db.xml";
            CaseFileNavigator fileNavigator = new CaseFileNavigator(testCaseFile);
            XElement globalSettingsXElement;
            globalSettingsXElement = fileNavigator.SelectGlobalSetting();

            DbConnectionConfigExtractor extractor = new DbConnectionConfigExtractor(testCaseFile, globalSettingsXElement);
            Assert.AreEqual("Data Source=VM_193", extractor["db3"].ConnectionString);
        }


        [Test, ExpectedException(typeof(DuplicateNameException))]
        public void TestConnectionNameUnique()
        {
            string testCaseFile = @"CaseFileSample\TestCase_V2_DbConn_SameName.xml";
            CaseFileNavigator fileNavigator = new CaseFileNavigator(testCaseFile);
            XElement globalSettingsXElement;
            globalSettingsXElement = fileNavigator.SelectGlobalSetting();

            DbConnectionConfigExtractor extractor = new DbConnectionConfigExtractor(testCaseFile, globalSettingsXElement);
        }



        [Test]
        public void TestDbConnExtractorIndex()
        {
            string testCaseFile = @"CaseFileSample\TestCase_V2_DbConn_3Db.xml";
            CaseFileNavigator fileNavigator = new CaseFileNavigator(testCaseFile);
            XElement globalSettingsXElement;
            globalSettingsXElement = fileNavigator.SelectGlobalSetting();

            DbConnectionConfigExtractor extractor = new DbConnectionConfigExtractor(testCaseFile, globalSettingsXElement);
            DbConnectionConfig entity= extractor["db1"];
            Assert.IsNotNull(entity) ;

            DbConnectionConfig entity2 = extractor["db4"];
            Assert.IsNull(entity2);
        }



        
    }

}
